//
//  UIBarButtonItem+Extension.swift
//  SWweibo
//
//  Created by 杜守鹏 on 15/12/27.
//  Copyright © 2015年 杜守鹏. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init(imageName:String?=nil,title:String?=nil,target:AnyObject?,action:Selector) {
      self.init()
        let button = UIButton()
        if(imageName != nil){
        button.setImage(UIImage(named: imageName!), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "\(imageName!)_highlighted"), forState: UIControlState.Highlighted)
        }
        if(title != nil ){
            button.setTitle(title, forState: UIControlState.Normal)
            button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
             button.titleLabel?.font = UIFont.systemFontOfSize(15)
        }
             button.sizeToFit()
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
            customView = button
    }
}







